Skip to content

Conversation

@jpodwys
Copy link

@jpodwys jpodwys commented May 8, 2016

I want to be able to use compression to enable GZIP on streamed responses that flush multiple chunks to the browser whenever the implementer wants. (This is especially useful when implementing a BigPipe algorithm such as with my express-stream library.) As a result, I need a sure way of flushing only after a chunk of output has been zipped.

Currently, the following code encounters a race condition because res.write is not blocking. As a result, it's possible that res.flush will execute before res.write completes.

res.write(html);
if(res.flush) res.flush();

I've confirmed the above by ensuring this works as expected:

res.write(html);
setTimeout(function(){
  if(res.flush) res.flush();
}, 10);

What I'd prefer to do, and what this PR enables, is the following:

res.write(html, null, function(){
  if(res.flush) res.flush();
});

@jpodwys
Copy link
Author

jpodwys commented May 9, 2016

I've made the same PR to the original compression as well. Doug and I are having some good discussion about it. Perhaps wait on this PR until Doug and I decide how best to accomplish my goal. Thanks for the awesome work!

@jpodwys jpodwys closed this May 24, 2016
scttdavs pushed a commit to scttdavs/shrink-ray that referenced this pull request Nov 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants